package thefirst.LessonBoard.model;

import java.sql.SQLException;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;

import thefirst.common.PagingBean;
import thefirst.member.model.MemberVO;

@Service
public class LessonBoardServiceImpl implements LessonBoardService {
	@Resource(name = "lessonBoardDaoImpl")
	private LessonBoardDao lessonBoardDao;

	@Override
	public void writeLessonBoard(LessonBoardVO lbvo) throws SQLException {
		//System.out.println("writeLessonBoard Service : "+ lbvo);
		lessonBoardDao.writeLessonBoard(lbvo);
	}

	@Override
	public LessonBoardListVO getLessonBoardList(String pageNo)
			throws SQLException {

		if (pageNo == null || pageNo == "") {
			pageNo = "1";
		}
		List<LessonBoardVO> list = lessonBoardDao.getLessonBoardList(pageNo);
		int total=lessonBoardDao.totalLessonContent();
		PagingBean paging = new PagingBean(total, Integer.parseInt(pageNo));
		LessonBoardListVO lbList = new LessonBoardListVO(list, paging);
		return lbList;
	}

	@Override
	public LessonBoardVO showLessonBoardInfoNoHits(LessonBoardVO lvo) throws SQLException {
		LessonBoardVO lbvo=lessonBoardDao.showLessonBoardInfoNoHits(lvo);
		//System.out.println("showLessonBoardInfoNoHits Service : "+lbvo);
		return lbvo;
	}

	@Override
	public LessonBoardVO showLessonInfo(LessonBoardVO lvo) throws SQLException {
		int result=lessonBoardDao.updateHits(lvo);
		LessonBoardVO lbvo=lessonBoardDao.showLessonBoardInfoNoHits(lvo);
		return lbvo;
	}

	@Override
	public void deleteLessonContent(LessonBoardVO lvo) throws SQLException {
		lessonBoardDao.deleteLessonContent(lvo);
		
	}

	@Override
	public int updateBoardContent(LessonBoardVO lvo)
			throws SQLException {
		return lessonBoardDao.updateBoardContent(lvo);
	}

}
